﻿using KinonekoSoftware.Foundation.Platform.Graphics;
using KinonekoSoftware.Studio.Pages.Galleries;


namespace KinonekoSoftware.Studio
{
    partial class Platform
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static Task<Result<InstanceCache>> NewInstance(InstanceType type)
        {
            var context = new DialogContext();
            context.Set(ContextBase.Key_Value, type);
            return ViewModelBase.Dialog<InstanceCache>(new NewInstanceViewModel(), context);
        }
        
        /// <summary>
        /// 创建二次分类的设定。
        /// </summary>
        /// <param name="type">源类型</param>
        /// <param name="extraTypes">二次分类类型</param>
        /// <param name="selector">二次分类本地化处理器。</param>
        /// <returns></returns>
        public static Task<Result<InstanceCache>> NewInstance(InstanceType type, IEnumerable<int> extraTypes, ObjectNameSelector selector)
        {
            var context = new DialogContext();
            context.Set(ContextBase.Key_Value, type);
            context.Set<IEnumerable<int>>("t", extraTypes);
            context.Set("s", selector);
            return ViewModelBase.Dialog<InstanceCache>(new NewInstanceViewModel(), context);
        }
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static Task<Result<InstanceCache>> NewInstance(string type)
        {
            var context = new DialogContext();
            context.Set(ContextBase.Key_Value2, type);
            return ViewModelBase.Dialog<InstanceCache>(new NewInstanceViewModel(), context);
        }
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <typeparam name="T"></typeparam>
        public static void GoTo<T>(PageContext context) where T : ViewModelBase, IPageRoot => (Ioc.Get<IViewService>() as ViewModelBase)?.GoTo<T>(context);
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="viewModel"></param>
        /// <param name="context"></param>
        public static void GoTo(IPageRoot viewModel, PageContext context) => (Ioc.Get<IViewService>() as ViewModelBase)?.GoTo(viewModel, context);

        public static async void OpenInstance(InstanceCache target)
        {
            var context = new PageContext
            {
                Id = target.Id,
            };

            //
            //
            context.Set(ContextBase.Key_Value, target);

        }


        /// <summary>
        /// 重写当前方法，来自定义跳转。
        /// </summary>
        /// <param name="target">要打开的设定索引。</param>
        public static void OpenTeam(InstanceCache target)
        {
            if (target is null)
            {
                return;
            }

            var context = new PageContext
            {
                Id = target.Id,
            };

            //
            //
            context.Set(ContextBase.Key_Value, target);



            if (target.Type != InstanceType.Team)
            {
                return;
            }

            //
            //
            var teamType = (TeamType)target.ExtraType;

        }

        private static void OpenWeapon(PageContext context, InstanceCache target)
        {
            //
            //
            var gunType = (WeaponType)target.ExtraType;

        }
    }
}